<html>
<head><meta charset="utf-8"><title>Non exhaustive reachable patterns lint lang-team#112 · t-lang/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/index.html">t-lang/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html">Non exhaustive reachable patterns lint lang-team#112</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246709756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/246709756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#246709756">(Jul 21 2021 at 12:06)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/lang-team/issues/112">Non exhaustive reachable patterns lint #112</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="246751026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/246751026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#246751026">(Jul 21 2021 at 17:23)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="1977">@T-lang</span>: Proposal <a href="https://github.com/rust-lang/lang-team/issues/112#issuecomment-884359258">#112</a> has been seconded, and will be approved in 10 days if no objections are raised.</p>



<a name="247068177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247068177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247068177">(Jul 24 2021 at 10:40)</a>:</h4>
<p>I've been working on two options, there is now a WIP lint inside <a href="http://usefulness.rs">usefulness.rs</a> and a normal lint (using the LateLintPass mechanics). There is a rather large problem in the normal lint, it cannot detect guards or or-patterns, basically it would have to use/reimplement parts of the mechanics of <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/check_match.rs">check_match</a>. It seems to me that adding the lint to the usefulness and check_match files makes sense.</p>
<p>I was able to make the lint work for <a href="https://github.com/DevinR528/rust/commit/df377ca309fd5acf1a3dcdcb90ecdfef9578eafb">enums</a> but am having trouble with structs and variants with fields <a href="https://github.com/DevinR528/rust/commits/useful-reachable">WIP commits</a> (first commit is the normal lint, the second two are an enum impl in usefulness and the start of me exploring for structs). For struct/variant fields I'm not really sure how to go about checking for the attribute (either place, see bellow) or the best way to skip the <code>..</code> rest/wildcard-ish and check for missing fields.</p>
<p>The other issue is where the attribute should be placed? In the <a href="https://github.com/rust-lang/rust/issues/84332">issue</a> as well as the <code>non_exhaustive</code> PR <a href="https://github.com/rust-lang/rust/issues/44109#issuecomment-521781237">comments</a> it was mentioned adding the attribute to the wildcard in a match</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="n">Bar</span>::<span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Bar</span>::<span class="n">A</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">    </span><span class="n">Bar</span>::<span class="n">B</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[deny(reachable)]</span><span class="w"> </span><span class="c1">// attribute goes here or on the expression</span>
<span class="w">    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// triggers lint "missing Bar::C..."</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The problem with this is that it's struct counterpart  isn't exactly valid <a href="https://github.com/rust-lang/rust/issues/81282">issue</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">a</span><span class="w"></span>
<span class="w">    </span><span class="n">b</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[warn(reachable)]</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="w"> </span><span class="c1">// triggers lint "missing field `c`..."</span>
<span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">structure</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>So the options, at least what I can come up with, are to make this valid or put the attribute on the expr/stmt instead of the wild patterns.</p>
<p>I also opened a compiler-team MCP <a href="https://github.com/rust-lang/compiler-team/issues/445">https://github.com/rust-lang/compiler-team/issues/445</a> should I close this or is this needed also?</p>



<a name="247094954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247094954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247094954">(Jul 24 2021 at 21:34)</a>:</h4>
<p>I don't know if you need a compiler MCP too, but I think the questions about <code>LateLintPass</code> vs something else are better in a compiler stream of some sort, since I at least have no idea how to answer those :P</p>
<p>As for the location (which I think <em>is</em> a lang question, though doesn't need to be resolved in the MCP), my question would be whether it could ever make sense on things like other arms than the last one.</p>
<p>For example, it could be phrased</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[warn(unmentioned_field)]</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">structure</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>since it's not like you'd want the "reachable" on other parts of the pattern, as far as I understand.  (And I think I prefer that form to the one that expands out all the fields to different lines.)</p>



<a name="247187674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247187674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247187674">(Jul 26 2021 at 10:55)</a>:</h4>
<blockquote>
<p>whether it could ever make sense on things like other arms than the last one.</p>
</blockquote>
<p>This is a good point, I agree that it probably won't ever be used on anything other than the last (wildcard). I wonder if it makes the intent more clear on the wildcard/rest pattern (like the examples in my above message)? Since it would be a whole thing to add the ability to put the attribute on struct rest patterns (<code>..</code>) I'm leaning towards putting the attribute on the expr/stmt as you showed in your example for structs and enums but this isn't a strong preference.</p>
<p>Is the next step waiting for the MCP to finish it's 10 days before discussing specifics or are we waiting on me to come up with a full implementation so it's easier to see pros/cons?</p>



<a name="247272882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247272882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247272882">(Jul 26 2021 at 22:37)</a>:</h4>
<p>Lints aren't a forever promise, so I think you should consider the MCP as "you're good to go on implementing it".  If some of the details change over the course of implementing that's fine.</p>
<p>Personally I see it more as a "make sure you don't waste time doing something that people will want to not happen at all" than something you strictly need to wait for.</p>



<a name="247273155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247273155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247273155">(Jul 26 2021 at 22:40)</a>:</h4>
<p>(Especially for something that's allow-by-default, right?  If you wanted to turn on something heuristic that would start warning on "did you maybe intend to add a case for qqqqqq?" then people would probably want another check-in before it turns on, but for an opt-in lint I suspect that the compiler folks will give plenty of review in PR if there's better ways of doing something.)</p>



<a name="247317718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20lang-team%23112/near/247317718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112.html#247317718">(Jul 27 2021 at 10:51)</a>:</h4>
<p>Cool sounds good thanks!! Back to learning all the ins and outs of usefulness checking <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span> hehe</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>